package com.chuangshixinchen.enterprise.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.chuangshixinchen.enterprise.common.JwtUtils;
import com.chuangshixinchen.enterprise.common.Result;
import com.chuangshixinchen.enterprise.common.StatusCode;
import com.chuangshixinchen.enterprise.entity.Tb_staff;
import com.chuangshixinchen.enterprise.entity.Tb_user;
import com.chuangshixinchen.enterprise.service.ITb_staffService;
import com.chuangshixinchen.enterprise.service.ITb_userService;
import com.chuangshixinchen.enterprise.vo.req.StaffReqPageVo;
import com.chuangshixinchen.enterprise.vo.req.UserChangePwdVo;
import com.chuangshixinchen.enterprise.vo.req.UserLoginVo;
import com.chuangshixinchen.enterprise.vo.req.UserReqPageVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Api(value = "员工模块", tags = "获取员工模块信息")
@RequestMapping("/staff")
public class StaffController {

    @Autowired
    private ITb_staffService staffService;

    @ApiOperation(value = "查询", notes = "根据token查询详情")
    @GetMapping(value = "/info/{id}")
    @ResponseBody
    public Result<Tb_staff> info(@RequestHeader("Authorization") String token, @PathVariable(value = "id") Long id) {
        if (!JwtUtils.checkToken(token)) {
            return new Result<Tb_staff>(false, StatusCode.AUTHORIZATION_ERROR, "授权失败！");
        }
        Result<Tb_staff> result = staffService.getInfo(id);
        return result;
    }

    @ApiOperation(value = "查询", notes = "分页查询")
    @PostMapping(value = "/page")
    @ResponseBody
    public Result<Page<Tb_staff>> page(@RequestHeader("Authorization") String token, @RequestBody StaffReqPageVo vo) {
        if (!JwtUtils.checkToken(token)) {
            return new Result<Page<Tb_staff>>(false, StatusCode.AUTHORIZATION_ERROR, "授权失败！");
        }
        Result<Page<Tb_staff>> result = staffService.listPage(vo);
        return result;
    }

    @ApiOperation(value = "删除", notes = "根据Id删除员工信息")
    @DeleteMapping(value = "/removeById/{ids}")
    @ResponseBody
    public Result save(@PathVariable(value = "ids") String ids, @RequestHeader("Authorization") String token) {
        if (!JwtUtils.checkToken(token)) {
            return new Result(false, StatusCode.AUTHORIZATION_ERROR, "授权失败！");
        }
        Result result = staffService.removeInfo(ids);
        return result;
    }

//    @ApiOperation(value = "新增", notes = "新增")
//    @PostMapping(value = "/save")
//    @ResponseBody
//    public Result save(@RequestHeader("Authorization") String token, @RequestBody Tb_staff staff) {
//        if (!JwtUtils.checkToken(token)){
//            return new Result(false, StatusCode.AUTHORIZATION_ERROR,"授权失败！");
//        }
//        Result result = staffService.saveInfo(staff);
//        return result;
//    }

//    @ApiOperation(value = "修改", notes = "修改")
//    @PutMapping(value = "/update")
//    @ResponseBody
//    public Result update(@RequestHeader("Authorization") String token, @RequestBody Tb_staff staff) {
//        if (!JwtUtils.checkToken(token)){
//            return new Result(false, StatusCode.AUTHORIZATION_ERROR,"授权失败！");
//        }
//        Result result = staffService.updateInfo(staff);
//        return result;
//    }
}
